package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/*
执行SELECT 语句
 */
public class JDBCDemo5 {
    public static void main(String[] args) {
        try(
                Connection connection=DBUtil.getConnection()
        ) {
            Statement statement=connection.createStatement();
            String sql="SELECT id,name,salary,title " +
                    "FROM teacher " +
                    "WHERE salary>8000";

            ResultSet resultSet = statement.executeQuery(sql);

            while(resultSet.next()){
                int id=resultSet.getInt("id");
                String name=resultSet.getString("name");
                int salary=resultSet.getInt("salary");
                String title=resultSet.getString("title");
                System.out.println(id+","+name+","+salary+","+title);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
